/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csci6450.chickenFriedFS.nuggetShell;

import csci6450.chickenFriedFS.nuggetClient.RuntimeSettings;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author jacobschoen
 */
public class Main {

    public static String LOG_NAME = "NuggetShell";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        List<String> errors = new ArrayList<String>();
        try {
            for (int i = 0; i < args.length; i = i + 2) {
                //-cp client listener port
                //-mlp meta listener port
                //-mip meta server ip
                //-mslp meta server listener port
                //-nl  nugget server log location
                //-cc  number of chunks to initialize
                //-fs filestore location

                if (args[i].equals("-mip")) {
                    RuntimeSettings.getInstance().setMetaServerIP(args[i+1]);
                } else if (args[i].equals("-mp")) {
                    try {
                        RuntimeSettings.getInstance().setMetaServerPort(Integer.parseInt(args[i + 1]));
                    } catch (NumberFormatException numberFormatException) {
                        errors.add("-mp must be followed by a positive integer.");
                    }
                } else if (args[i].equals("-h")) {
                    errors.add("Following is the list of arguments that can be used to start the Nugget Server:");
                    errors.add("  '-mip'  The Port that this Nugget Server will listen for Client requests on.");
                    errors.add("  '-mp'   The Port that this Nugget Server will listen for Meta Server Requests");
                    errors.add("          on.");
                    errors.add("  '-h'    This will print the information above.");
                }

            }
            if (errors.size() == 0) {
                new NuggetShell().run();
            } else {
                //mean something went wrong tell the user
                for (int i = 0; i < errors.size(); i = i + 1) {
                    System.out.println(errors.get(i));
                }
                System.exit(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}
